package org.jsola.hr.helper;

import org.jsola.hr.dto.PolicyPermissionsAddDTO;
import org.jsola.hr.dto.PolicyPermissionsUpdateDTO;
import org.jsola.hr.entity.PolicyPermissionsDO;
import org.jsola.hr.query.PolicyPermissionsQuery;
import org.jsola.hr.service.IPolicyPermissionsService;
import org.jsola.hr.vo.PolicyPermissionsVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * 政策速递权限
 *
 * @author zhr
 */
@Component
public class PolicyPermissionsTestHelper extends BaseTestHelper {
    
    @Autowired
    private IPolicyPermissionsService policyPermissionsService;

    /**
     * 生成add测试数据
     * @return PolicyPermissionsAddDTO
     */
    public PolicyPermissionsAddDTO getPolicyPermissionsAddDTO(){
        PolicyPermissionsAddDTO policyPermissionsAddDTO = new PolicyPermissionsAddDTO();
        policyPermissionsAddDTO.setPolicyId(getRandomValue("varchar",32));
        policyPermissionsAddDTO.setPermissionsType(getRandomValue("varchar",32));
        policyPermissionsAddDTO.setPermissionsId(getRandomValue("varchar",32));
        return policyPermissionsAddDTO;
    }


    /**
     * 生成update测试数据
     * @return PolicyPermissionsUpdateDTO
     */
    public PolicyPermissionsUpdateDTO getPolicyPermissionsUpdateDTO(PolicyPermissionsVO policyPermissionsVO){
        return policyPermissionsService.selectDOById(policyPermissionsVO.getId(), SITE_ID).to(PolicyPermissionsUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return PolicyPermissionsQuery
     */
    public PolicyPermissionsQuery getPolicyPermissionsQuery() {
        PolicyPermissionsQuery policyPermissionsQuery = new PolicyPermissionsQuery();
        List<PolicyPermissionsDO> policyPermissionsDOList = policyPermissionsService.list(new PolicyPermissionsDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(policyPermissionsDOList)) {
            PolicyPermissionsDO policyPermissionsDO = policyPermissionsDOList.get(0);
            policyPermissionsQuery = policyPermissionsDO.to(PolicyPermissionsQuery.class);
        }
        return policyPermissionsQuery;
    }

    /**
     * 保存示例
     * @return PolicyPermissionsVO
     */
    public PolicyPermissionsVO savePolicyPermissionsExample(){
        PolicyPermissionsAddDTO addDTO = this.getPolicyPermissionsAddDTO();
        PolicyPermissionsVO policyPermissionsVO = policyPermissionsService.save(addDTO,buildTokenUser());
        return policyPermissionsVO;
    }


}

